#include "s3c2440_soc.h"
void sdram_init()
{
    BWSCON = 0x22000000;
    BANKCON6 = 0x18001;
    BANKCON7 = 0x18001;

    REFRESH = 0x8404f5;
    BANKSIZE = 0xb1;
    MRSRB6 = 0X20;
    MRSRB7 = 0X20;
}

int sdram_test(void)
{

    volatile unsigned int* p = (volatile unsigned int *) 0x30000000;
    int i;

    //write sdram
    for(i = 0; i<1000;i++)
	p[i] = 0x55;

    //read sdram
    for(i = 0;i<1000;i++)
	if(p[i] != 0x55)
	    return -1;

    return 0;
}

void copy2sdram(void)
{
    /*
     * 要从lds文件中获得 _code_start,_bss_start
     * 然后从0地址把数据复制到_code_start
     */
    extern int _code_start,_bss_start;

    volatile unsigned int *dest = (volatile unsigned int*)&_code_start;
    volatile unsigned int *end = (volatile unsigned int*)&_bss_start;
    volatile unsigned int *src = (volatile unsigned int*)0;

    while(dest < end){
	*dest++ = *src++;
    }
}

void clean_bss(void)
{
    extern int _end,_bss_start;

    volatile unsigned int *start = (volatile unsigned int*)&_bss_start;
    volatile unsigned int *end = (volatile unsigned int*)&_end;
    
    while(start <= end){
	*start++ = 0;
    }
}
